﻿-- =================================
-- Populate the dbo.Users table.
-- =================================
declare @t table
(
    [Name]         NVARCHAR (50)  NOT NULL UNIQUE,
    [Email]        NVARCHAR (100) NOT NULL UNIQUE,
    [Password]     NVARCHAR (128) NOT NULL,
    [PasswordSalt] NVARCHAR (128) NOT NULL,
    [RoleId]       INT            NOT NULL
);
--
insert into @t([Name], [Email], [Password], [PasswordSalt], [RoleId])
values
(N'Admin', N'admin@grig.com', N'D86534E36532098B8A4164A8F9175904F2B65A09', N'mQOwmROX5swt48C4DTUCGnnaUVS2QfS9L+Yhxev5v8Q=', '4');
--
merge into [dbo].[Users] as [target]
using @t as [source] on [target].[Name] = [source].[Name] AND [target].[Email] = [source].[Email]
when matched then
	update set [target].[Password] = [source].[Password],
			   [target].[PasswordSalt] = [source].[PasswordSalt],
			   [target].[RoleId] = [source].[RoleId]
when not matched by target then
	insert ([Name], [Email], [Password], [PasswordSalt], [RoleId])
	values ([source].[Name], [source].[Email], [source].[Password], [source].[PasswordSalt], [source].[RoleId])
when not matched by source then
	delete;
go